<?php

/**
 * UserController
 * 
 * @author
 * @version 
 */

require_once 'Zend/Controller/Action.php';

class RegisterController extends Zend_Controller_Action {
		
	public function indexAction() {
		$this->view->form = new FormRegister ( array ('action' => $this->getFrontController()->getBaseUrl().'/register/save' ) );
	}
	
	public function saveAction() {
		
		if ($this->getRequest()->isPost()) {
	
			$formData = $this->getRequest()->getPost();
					
			$form = new FormRegister();
					
			if ($form->isValid($formData)) {
				$formData['pass']  = sha1($formData['pass']);	
				$users = new Users();
				$user = $users->createRow($formData);
				$user->save();
				$this->_redirect('index');
				
			} else {
				$this->view->form = $form;
				$this->render('index');			
			}
			
		}
	}
	
}
?>